home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / DINKDEMO / DINKCLAS / DWINDOW.C < prev    next >
Text File  |  1992-07-07  |  6KB  |  336 lines

  1. /*
  2.     File:        DWindow.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    ⌐ 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10.  
  11. // the is the Class definition for the DWindow class
  12.  
  13.  
  14. #include "DWindow.h"
  15. #include "DDocument.h"
  16. #include "DEventHandler.h"
  17.  
  18.  
  19. DWindow::DWindow(void)
  20. {
  21.     //stub!!
  22. }
  23.  
  24.  
  25. DWindow::~DWindow(void)
  26. {
  27.     DisposHandle( fPrintRecord);
  28. }
  29.     
  30.     
  31. Boolean DWindow::Init(DDocument *doc, Boolean hasColorWindows)
  32. {
  33.     WindowPtr prevFrontWindow;
  34.     Point corner;
  35.     Rect r;
  36.  
  37.     SetRect(&r, 0,0,0,0);
  38.     
  39.     fVOffSet = 0;
  40.     fHOffSet = 0;
  41.         //set up the print record with the last printer settings
  42.     fPrintRecord = (THPrint) NewHandle(sizeof(TPrint) );
  43.     if(fPrintRecord != NULL)
  44.     {
  45.         PrOpen();
  46.         PrintDefault(fPrintRecord);
  47.         PrClose();
  48.     }
  49.  
  50.     prevFrontWindow =  FrontWindow();
  51.     if(prevFrontWindow != NULL)
  52.     {
  53.         SetPort( prevFrontWindow);
  54.         corner.v = prevFrontWindow->portRect.top;
  55.         corner.h = prevFrontWindow->portRect.left;
  56.         LocalToGlobal(&corner);
  57.     }    
  58.     
  59.     fDoc = doc;
  60.     
  61.     if(hasColorWindows)
  62.         fWindowPtr = GetNewCWindow(rWindowID, NULL, (WindowPtr)-1L);
  63.     else
  64.         fWindowPtr = GetNewWindow(rWindowID, NULL, (WindowPtr)-1L);
  65.     
  66.     if(fWindowPtr)
  67.     {
  68.         fNextHandler = fDoc;
  69.         SetWRefCon(fWindowPtr, (long)this);    // tie this to window for activate events!!
  70.         if(prevFrontWindow != NULL)
  71.             MoveWindow(fWindowPtr, corner.h + kStagger, corner.v + kStagger, TRUE);
  72.         ShowWindow(fWindowPtr);
  73.  
  74.         return TRUE;
  75.     }
  76.     else
  77.     {
  78.         KillMeNext();
  79.         return FALSE;
  80.     }
  81.         
  82. }
  83.     
  84. void DWindow::Draw( Rect *area)
  85. {
  86.     EraseRect(area);
  87. }
  88.  
  89.  
  90.  
  91. void DWindow::HandleUpdateEvt(EventRecord *theEvent)
  92. {
  93.     SetPort (fWindowPtr);
  94.     BeginUpdate (fWindowPtr);
  95.     if( !EmptyRgn(fWindowPtr->visRgn) )
  96.         Draw( &(fWindowPtr->portRect));
  97.     DrawGrowIcon( fWindowPtr);
  98.     EndUpdate(fWindowPtr);
  99.     
  100.     inherited::HandleUpdateEvt(theEvent);
  101. }
  102.  
  103.     
  104. void DWindow::HandleActivateEvt(EventRecord *theEvent)
  105. {
  106.     Boolean    activating;
  107.     
  108.     FocusOnContent();
  109.     if( !EmptyRgn(fWindowPtr->visRgn) )
  110.         Draw( &(fWindowPtr->portRect));
  111.     DrawGrowIcon(fWindowPtr);
  112.     
  113.     inherited::HandleActivateEvt(theEvent);
  114. }
  115.  
  116.     
  117. void DWindow::Close(void)
  118. {
  119.     fDoc->WindowClosed(this);
  120.     KillMeNext();
  121. }
  122.  
  123.  
  124. void DWindow::KillMeNext(void)
  125. {
  126.     if(fAlive)
  127.     {
  128.         inherited::KillMeNext();
  129.         fDoc->WindowClosed(this);
  130.         DisposeWindow( fWindowPtr );
  131.     }
  132. }
  133.  
  134. void DWindow::HandleMouseDown(EventRecord *theEvent, short thePart, WindowPtr theWindow)
  135. {
  136.     if (theWindow == fWindowPtr)
  137.     {
  138.         switch( thePart)
  139.         {
  140.             case     inGoAway:
  141.                 if (TrackGoAway(theWindow, theEvent->where) )
  142.                     Close();
  143.                 break;
  144.             
  145.             case    inDrag:
  146.                     DoDrag(theEvent);
  147.                 break;
  148.             
  149.             case    inGrow:
  150.                     DoGrow(theEvent);
  151.                 break;
  152.             
  153.             case    inZoomIn:
  154.             case    inZoomOut:
  155.                 if( TrackBox( theWindow, theEvent->where, thePart) ) 
  156.                     DoZoom(thePart);
  157.                 break;
  158.             
  159.             case    inContent:
  160.                 DoContent(theEvent);
  161.                 break;
  162.         }// end switch
  163.     }
  164.     else
  165.         ; // do nothing but pass it on
  166.     
  167.     inherited::HandleMouseDown(theEvent, thePart, theWindow);
  168. }
  169.  
  170.  
  171. void DWindow::DoDrag(EventRecord *theEvent)
  172. {
  173.     RgnHandle    theGrayRgn;
  174.     Rect        r;
  175.     
  176.     theGrayRgn = GetGrayRgn();
  177.     r = (**theGrayRgn).rgnBBox;
  178.     
  179.     DragWindow(fWindowPtr, theEvent->where, &r);
  180.  
  181. }// end member function DoDrag
  182.  
  183.  
  184. void DWindow::DoGrow(EventRecord *theEvent)
  185. {
  186.     long        result;
  187.     RgnHandle    theGrayRgn;
  188.     Rect        r;
  189.     
  190.     theGrayRgn = GetGrayRgn();
  191.     r = (**theGrayRgn).rgnBBox;
  192.     r.top = MINHIGHT; r.left = MINWIDTH;
  193.     SetPort(fWindowPtr);
  194.     result = GrowWindow(fWindowPtr, theEvent->where, &r);
  195.     
  196.     if(result != 0)
  197.     {
  198.         r = fWindowPtr->portRect;
  199.         r.left = r.right - kScrollBarPos;
  200.         InvalRect(&r);
  201.         EraseRect(&r);
  202.         r = fWindowPtr->portRect;
  203.         r.top = r.bottom - kScrollBarPos;
  204.         InvalRect(&r);
  205.         EraseRect(&r);
  206.         
  207.         SizeWindow(fWindowPtr, LoWrd(result), HiWrd(result), TRUE);
  208.         
  209.         r = fWindowPtr->portRect;
  210.         r.left = r.right - kScrollBarPos;
  211.         InvalRect(&r);
  212.         EraseRect(&r);
  213.         r = fWindowPtr->portRect;
  214.         r.top = r.bottom - kScrollBarPos;
  215.         InvalRect(&r);
  216.         EraseRect(&r);
  217.     }// end if 
  218. }// end of member function DoGrow
  219.  
  220.  
  221. void DWindow::DoZoom(short thePart)
  222. {    
  223.     SetPort(fWindowPtr);
  224.     EraseRect(&fWindowPtr->portRect);
  225.     ZoomWindow(fWindowPtr, thePart, fWindowPtr == FrontWindow());
  226.     
  227.     InvalRect(&fWindowPtr->portRect);
  228. }// end member function DoZoom
  229.     
  230.  
  231. void DWindow::DoContent(EventRecord *theEvent)
  232. {
  233.  
  234.     ; // stub!!
  235.  
  236. }// end member function DoContent
  237.  
  238.  
  239.  
  240. void    DWindow::DoPageSetUp(void)
  241. {
  242.     PrOpen();
  243.     (void)PrStlDialog(fPrintRecord);
  244.     PrClose();
  245. }
  246.  
  247.  
  248. void    DWindow::DoPrint(void)
  249. {
  250.     TPPrPort    printPort;
  251.     Rect        r;
  252.     TPrStatus    status;
  253.     THPrint        tmpPrintRecord;
  254.     
  255.     tmpPrintRecord = fPrintRecord;
  256.     PrOpen();
  257.     if (PrValidate(tmpPrintRecord) )
  258.         if (!PrStlDialog(tmpPrintRecord) )
  259.         {
  260.             PrClose();
  261.             return;
  262.         }
  263.         
  264.     if (!PrJobDialog(tmpPrintRecord) )
  265.     {
  266.         PrClose();
  267.         return;
  268.     }
  269.     
  270.     printPort = PrOpenDoc(tmpPrintRecord, NULL, NULL);
  271.     
  272.     PrOpenPage(printPort, NULL);
  273.     
  274.     SetRect(&r, 0, 0, 0, 0);
  275.     Draw(&r);
  276.     
  277.     PrClosePage(printPort);
  278.     
  279.     PrCloseDoc(printPort);
  280.     
  281.     if ((**tmpPrintRecord).prJob.bJDocLoop != 0)
  282.         PrPicFile(tmpPrintRecord, NULL, NULL, NULL, &status);
  283.         
  284.     PrClose();
  285.     // now clean up the mess we made on the screen!!!
  286.     
  287.     FocusOnWindow();
  288.     InvalRgn( ((WindowPeek)fWindowPtr)->contRgn);
  289. }
  290.  
  291.  
  292. void DWindow::SetWindowTitle(void)
  293. {
  294.     StringPtr title;
  295.     
  296.     if(fDoc->fFileRef != 0) //fFileRef is the file open flag.
  297.     {
  298.         title = (fDoc->fFileReply->sfFile).name;
  299.         SetWTitle(fWindowPtr, title);
  300.     }
  301. }
  302.  
  303. void    DWindow::FocusOnContent(void)
  304. {
  305.     Rect r;
  306.     
  307.     SetPort(fWindowPtr);
  308.     SetOrigin(fHOffSet, fVOffSet);
  309.     GetContentRect(&r);
  310.     ClipRect(&r);
  311. }/*end of function*/
  312.  
  313.  
  314. void    DWindow::FocusOnWindow(void)
  315. {
  316.     Rect r;
  317.     
  318.     SetPort(fWindowPtr);
  319.     SetOrigin(0,0);
  320.     r = fWindowPtr->portRect;
  321.     ClipRect(&r);
  322. }/*end of function*/
  323.     
  324.  
  325. void    DWindow::GetContentRect(Rect *r)
  326. {
  327.     *r = fWindowPtr->portRect;
  328.     r->right -= kScrollBarPos;
  329.     r->bottom -= kScrollBarPos;
  330. }/*end of function*/
  331.  
  332.     
  333.     
  334.     
  335.     
  336.